//
//  TrackDayTableViewCell.m
//  NNing
//
//  Created by ym on 16/8/11.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "TrackDayTableViewCell.h"

#import "PhotosContainerView.h"
#import "UserLikeView.h"

@implementation TrackDayTableViewCell
{
    PhotosContainerView *_photosContainer;
    UserLikeView *_UserLikeView;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}



- (void)awakeFromNib {
    [super awakeFromNib];
    
    PhotosContainerView *photosContainer = [[PhotosContainerView alloc] initWithMaxItemsCount:9];
    _photosContainer = photosContainer;
    
    UserLikeView *a = [[UserLikeView alloc] init];
    _UserLikeView = a;
    [self.contentView addSubview:a];
    [self.contentView addSubview:photosContainer];
    self.UserName.font = [UIFont fontWithName:AppFont size:18];
    self.UserName.textColor = [UIColor blackColor];
    self.TimeLabel.font = [UIFont fontWithName:AppFont size:10];
    self.TimeLabel.textColor = [UIColor grayColor];
    self.NeiRongLabel.font = [UIFont fontWithName:AppFont size:15];
    self.NeiRongLabel.textColor = [UIColor grayColor];
    
    self.UserImage.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 10)
    .widthIs(50)
    .heightIs(50);
    
    self.UserImage.layer.cornerRadius = self.UserImage.frame.size.width / 2;
    self.UserImage.layer.masksToBounds = YES;
    
    self.UserName.sd_layout
    .leftSpaceToView(self.UserImage,10)
    .topEqualToView(self.UserImage)
    .rightSpaceToView(self.contentView,10).heightIs(20);
    
    self.TimeLabel.sd_layout
    .leftEqualToView(self.UserName)
    .topSpaceToView(self.UserName,1)
    .rightSpaceToView(self.contentView,10).heightIs(20);
    
    
    self.NeiRongLabel.sd_layout
    .leftSpaceToView(self.UserImage, 10)
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(self.TimeLabel,10)
    .autoHeightRatio(0);
    
    
    
    
    _photosContainer.sd_layout
    .leftEqualToView(self.NeiRongLabel)
    .rightEqualToView(self.NeiRongLabel)
    .topSpaceToView(self.NeiRongLabel, 1);
    
//    _WNY_UserLikeView.sd_layout.leftEqualToView(self.UserName).rightSpaceToView(self.contentView,10).topSpaceToView(_photosContainer,10).heightIs(30);
//    _WNY_UserLikeView.backgroundColor = [UIColor redColor];
    
    
    
}


- (void)setModel:(TrackDayModel *)model{
    _model = model;
    
    _NeiRongLabel.text= model.title;
    [_UserImage setImage:[UIImage imageNamed:model.iconImagePath] forState:UIControlStateNormal];
    
    [_UserImage addTarget:self action:@selector(othersHomePageee) forControlEvents:UIControlEventTouchUpInside];
    _TimeLabel.text = model.time;
    _UserName.text = model.userName;
    UIView *bottomView = _NeiRongLabel;
    _UserLikeView.imageArr = model.imageLike;
    _photosContainer.photoNamesArray = model.imagePathsArray;
    NSMutableArray *muArr = [NSMutableArray arrayWithObjects:_UserImage,_UserName,_TimeLabel,_NeiRongLabel,_UserLikeView, nil];
    if (model.imagePathsArray.count > 0) {
        _photosContainer.hidden = NO;
        bottomView = _photosContainer;
        [muArr addObject:_photosContainer];
        _UserLikeView.sd_layout.leftEqualToView(self.UserName).rightSpaceToView(self.contentView,10).topSpaceToView(_photosContainer,10).heightIs(30);

    } else {
        _UserLikeView.sd_layout.leftEqualToView(self.UserName).rightSpaceToView(self.contentView,10).topSpaceToView(_NeiRongLabel,10).heightIs(30);

        _photosContainer.hidden = YES;

    }

//    NSArray *arr = @[_UserImage,_UserName,_TimeLabel,_NeiRongLabel,_photosContainer];
//    [self setupAutoHeightWithBottomView:bottomView bottomMargin:10];
    [self setupAutoHeightWithBottomViewsArray:muArr bottomMargin:10];

}


- (void)othersHomePageee{
    _othersHomePage();
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
